//
//  UImageView+Extension.swift
//  WeiBo
//
//  Created by DDC on 2017/9/15.
//  Copyright © 2017年 DDC. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    func jcl_setImageView(urlString:String?,placeholderImage:UIImage,isAvater:Bool = false) {
        
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
            
            image = placeholderImage
            
            return
        }
        
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { (image, _, _, _) in
            
            if isAvater && image != nil {
               self.image =  image?.JCLAvatarImage(image: image!, size: self.bounds.size, backColor: UIColor.white)
            }
        }
        
        
    }
    
    func jcl_setImageView(urlString:String?) {
        
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
                
                return
        }
        sd_setImage(with: url)
    }
    
}
